<?php
	
	//如果用户已经登录则跳转到用户首页
	if(isset($_SESSION['IS_LOGGED']) && $_SESSION['IS_LOGGED'])
	{
		header('Location: ' . SITEURL . 'home');
	}
	else
	{
		//如果输入参数不完整，则继续输入
		if(	!isset($_POST['username']) 
			|| empty($_POST['username']) 
			|| !isset($_POST['nickname'])
			|| empty($_POST['nickname'])
			|| !isset($_POST['passwd'])
			|| empty($_POST['passwd'])
			|| !isset($_POST['passwdagain'])
			|| empty($_POST['passwdagain'])
			|| !isset($_POST['nickname'])
			|| empty($_POST['nickname'])
			|| !isset($_POST['email'])
			|| empty($_POST['email'])
			|| !isset($_POST['city'])
			|| empty($_POST['city']))
			{
				$html = '
					<form name="userlogin" method="post" action="' . SITEURL . 'userreg">
					用户名:
						<input type="text" name="username"><br/>
					密码:
						<input type="password" name="passwd"><br/>
					再次输入密码:
						<input type="password" name="passwdagain"><br/>
					昵称:
						<input type="text" name="nickname"><br/>
					email:
						<input type="text" name="email"><br/>
					所在城市:
						<input type="text" name="city"><br/>
						<input type="submit" name="login_submit" value="注册">
					</form>
				';
			}
			else
			{
				//注册数据正确，进行用户注册，注册结束后跳转到登录界面引导用户登录
				if(reg_new_user($_POST['username'],$_POST['passwd'],$_POST['passwdagain'],$_POST['nickname'],$_POST['email'],$_POST['city']))
				{
					header('Location: ' . SITEURL . 'login');
				}
				else
				{
					header('Location: ' . SITEURL . 'userreg');
				}
			}
	}
?>